package com.emns.service.mobile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emns.dao.LanmuZiyuanMapper;
import com.emns.dao.YueduMapper;
import com.emns.dao.YueduScoreMapper;
import com.emns.pojo.LanmuZiyuan;
import com.emns.pojo.Yuedu;
import com.emns.pojo.YueduScore;
import com.emns.pojo.YueduScoreExample;
import common.PageInfo;

@Service
public class YueduMobileService {

	@Autowired
	YueduMapper ydm;
	@Autowired
	LanmuZiyuanMapper lzm;
	@Autowired
	YueduScoreMapper ysm;

	public void queryPageAll(String keyWord, Integer fLanmu, Integer sLanmu,
			PageInfo<Yuedu> pageInfo) {
		LanmuZiyuan lmZiyuan = null;
		if (keyWord != null && !"".equals(keyWord))
			keyWord = "%" + keyWord + "%";
		else
			keyWord = null;
		if (fLanmu != null && sLanmu != null) {
			lmZiyuan = new LanmuZiyuan();
			lmZiyuan.setFirstLanmuId(fLanmu);
			lmZiyuan.setSecondLanmuId(sLanmu);
		}
		List<Yuedu> yuduList = ydm.getMobileRecordPage(keyWord, lmZiyuan,
				pageInfo);
		int count = ydm.getMobileRecordCount(keyWord, lmZiyuan, pageInfo);
		pageInfo.setDataArray(yuduList);
		pageInfo.setPageCount(count);
	}

	// 根据阅读编号获取阅读信息
	public Map<String, Object> getYueduById(Integer yueduId,
			Integer commentUserId) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("yuedu", ydm.selectByPrimaryKey(yueduId));
		YueduScoreExample yse = new YueduScoreExample();
		yse.createCriteria().andTUserUserIdEqualTo(commentUserId)
				.andTYueduYueduIdEqualTo(yueduId);
		List<YueduScore> ysList = ysm.selectByExample(yse);
		if (ysList.size() > 0) {
			hashMap.put("commentUserId", ysList.get(0));
		} else {
			hashMap.put("commentUserId", null);
		}
		return hashMap;
	}
}
